const AudioControl = require('./audio-control')
const ChildProcess = require('child_process');

// const audio = new AudioControl()
const { PromisifyExec } = require('../lib')

async function camera_list() {
    let buf = await PromisifyExec('v4l2-ctl --list-devices')
    let out = buf.toString()
    devices = out.split('\n\n')
    console.log(devices)
    for (let i = 0; i < devices.length; i++) {
        const element = devices[i];
        let device = element.split('\n\t')
        if (device.length > 0) {
            if (device[0].indexOf('Camera') > 0) {
                for (let j = 1; j < device.length; j++) {
                    const element = device[j];
                    console.log(element)
                }
            }
        }
        console.log(device)
    }
}

const path = require('path');
// camera_list()
(async () => {
    const { LowSync, JSONFileSync } = await import('lowdb')
    const db = new LowSync(new JSONFileSync(path.join(__dirname, '../../config.json')))
    db.read()
    console.log(db)
    if (!db.data) {
        db.data = { wifi: {}, env: { lang: 'en' } };
        db.write()
    }
})().then(console.log('db init done'));